//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using System.Windows.Media;

namespace OpenLS.Spreadsheet
{
    static class StandardPalette
    {
        public static Color GetTextColor(int index)
        {
            if (index == 0x7FFF)
                return Colors.Black;
            return GetColor(index);
        }
        public static Color GetColor(int index)
        {
            if (index < StandardColors.Length)
            return StandardColors[index];
        return Colors.White;
        }
        public static bool GetColorIndex (Color color, out int index)
        {
            ensureBackTable();
            return backTable.TryGetValue(color, out index);
        }
        static void ensureBackTable()
        {
            if (backTable != null)
                return;
            for (int i = 0; i < StandardColors.Length; i++)
                backTable[StandardColors[i]] = i;
        }
        static readonly Dictionary<Color, int> backTable = new Dictionary<Color,int>();
        static readonly Color[] StandardColors = new Color[]
            {
                Colors.Black, // 0
                Colors.White,
                Colors.Red,
                Colors.Lime,
                Colors.Blue,
                Colors.Yellow,
                Colors.Fuchsia,
                Colors.Aqua,
                Colors.Black,
                Colors.White,
                Colors.Red, // 10
                Colors.Lime,
                Colors.Blue,
                Colors.Yellow,
                Colors.Fuchsia,
                Colors.Aqua,
                Colors.Maroon,
                Colors.Green,
                Colors.Navy,
                Colors.Olive,
                Colors.Purple, //20
                Colors.Teal,
                Colors.Silver,
                Colors.Gray,
                Color.FromArgb(255, 153, 153, 255),
                Color.FromArgb(255, 153, 51, 102),
                Color.FromArgb(255, 255, 255, 204),
                Color.FromArgb(255, 204, 255, 255),
                Color.FromArgb(255, 102, 0, 102),
                Color.FromArgb(255, 255, 128, 128),
                Color.FromArgb(255, 0, 102, 204), //30
                Color.FromArgb(255, 204, 204, 255),
                Colors.Navy,
                Colors.Fuchsia,
                Colors.Yellow,
                Colors.Aqua,
                Colors.Purple,
                Colors.Maroon,
                Colors.Teal,
                Colors.Blue,
                Color.FromArgb(255, 0, 204, 255), // 40
                Color.FromArgb(255, 204, 255, 255),
                Color.FromArgb(255, 204, 255, 204),
                Color.FromArgb(255, 255, 255, 153),
                Color.FromArgb(255, 153, 204, 255),
                Color.FromArgb(255, 255, 153, 204),
                Color.FromArgb(255, 204, 153, 255),
                Color.FromArgb(255, 255, 204, 153),
                Color.FromArgb(255, 51, 102, 255),
                Color.FromArgb(255, 51, 204, 204),
                Color.FromArgb(255, 153, 204, 0),// 50
                Color.FromArgb(255, 255, 204, 0),
                Color.FromArgb(255, 255, 153, 0),
                Color.FromArgb(255, 255, 102, 0),
                Color.FromArgb(255, 102, 102, 153),
                Color.FromArgb(255, 150, 150, 150),
                Color.FromArgb(255, 0, 51, 102),
                Color.FromArgb(255, 51, 153, 102),
                Color.FromArgb(255, 0, 51, 0),
                Color.FromArgb(255, 51, 51, 0),
                Color.FromArgb(255, 153, 51, 0),//60
                Color.FromArgb(255, 153, 51, 102),
                Color.FromArgb(255, 51, 51, 153),
                Color.FromArgb(255, 51, 51, 51),
                Colors.Black,
                Colors.White,
                Colors.Black,
                Color.FromArgb(255, 236, 233, 216),
                Colors.Black,
                Colors.White,
                Color.FromArgb(255, 172, 168, 153), // 70
                Color.FromArgb(255, 49, 106, 197),
                Colors.Black,
                Color.FromArgb(255, 212, 208, 200),
                Color.FromArgb(255, 43, 47, 55),
                Colors.White,
                Colors.Black,
                Colors.Black,
                Colors.White,
                Colors.Black,
                Color.FromArgb(255, 255, 255, 225), // 80
                Colors.Black,
                Colors.White,
                Colors.White,
                Colors.White,
                Colors.White,
            };
    }
}
